// pages/activity/pay/submitOrder/submitOrder.js
const app = getApp()
var http = require("../../../../utils/httpUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempName: "游客"+parseInt(new Date()/1000),
    region: ['陕西省', '西安市', '雁塔区'],
    sexs: [{
        value: '0',
        name: '男',
        checked: 'true'
      },
      {
        value: '1',
        name: '女'
      },
    ],
    activityId : 0,
    organizationId : 0,
    dataInfo : {}
  },
  
  formSubmit(e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    // wx.navigateTo({
    //   url: '../checkOrder/checkOrder' + '?ono=6863',
    // })
    // return
    console.log('用户信息：' , wx.getStorageSync('userInfo'))
    var urls = app.globalData.SERVER_IP+"/order/add_order"
    var params = {
      "o_custom": "[{type:1,course_count:48,f_id:0,diff_count:undefined,fu_price:undefined,fu_count:undefined}]",
      "o_oid": this.data.dataInfo.o_id,
      "o_uid": wx.getStorageSync('userInfo').userid,
      "o_name": e.detail.value.name,
      "o_phone": e.detail.value.phone,
      "o_age": e.detail.value.age,
      "o_sex": e.detail.value.sex,
      "o_address": e.detail.value.addDetail,
      "o_type": this.data.dataInfo.o_type,
      "o_pay_money": this.data.dataInfo.new_price,
      "o_money": this.data.dataInfo.new_price,
      "o_aoc_id": this.data.dataInfo.activityId,
      "o_coupon_id": "",
      "o_note": e.detail.value.remark,
      "o_preferential_money": 0,
      "o_balance_pay": 0,
      "o_wechat_pay": this.data.dataInfo.new_price,
      "o_old_price": this.data.dataInfo.old_price,
      "o_new_price": this.data.dataInfo.new_price,
      "o_organization_name": this.data.dataInfo.o_organization_name,
      "o_course_name": this.data.dataInfo.title,
      "o_course_pic": this.data.dataInfo.title_image,
      "o_pay_type": 0,
      "o_activity_type": this.data.dataInfo.o_activity_type
    }

    // 下单
		http.P(urls, params, (res) => {
      console.log(res.result)
      if (res.success) {
        wx.navigateTo({
          url: '../checkOrder/checkOrder' + '?ono=' + res.result,
        })
      }
		}, (err) => {
			console.log("获取首页数据失败")
			console.log(err)
		})

  },

  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },

  radioChange: function (e) {
    console.log(e.detail.value)
    const items = this.data.sexs
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }

    this.setData({
      items
    })
  },

  submitBtn: function (e) {
    console.log("订单创建页点击了提交按钮！")
    // 查询登录信息
    console.log(wx.getStorageSync('userInfo'))

    return
    wx.navigateTo({
      url: '../checkOrder/checkOrder',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.data.activityId = options.activityId
    this.data.organizationId = options.o_id

    this.setData({
      dataInfo : options
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({
		})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})